Return to start page

Core/Maths/Library Real.j

Code

		
1			library ALibraryCoreMathsReal
2
3 /**
4 * @author WaterKnight
5 * @source http://www.inwarcraft.de/
6 * Siehe RoundTo.
7 */
8 private function RoundToGetDifference takes real dividend, real divisor returns real
9 return RAbsBJ(dividend - R2I(dividend / divisor) * divisor)
10 endfunction
11
12 /**
13 * @author WaterKnight
14 * @return Gibt das von base nächstgelegene Vielfache von interval zurck. Also praktisch ein allgemeines Runden. Ist @param interval 0, so gibt die Funktion 0 zurück.
15 * Sollte der Abstand gleich sein, hat das Ergebnis mit dem kleineren Betrag Vorrang. RoundToGetDifference ist für RoundTo gedacht, deswegen habe ich eine Sicherheitsmanahme, die eine Nulldivision verhindern würde, ausgelassen, da diese schon bei RoundTo stattfindet.
16 */
17 function RoundTo takes real base, real interval returns real
18 local real difference1
19 local real difference2
20 if (interval == 0) then
21 return 0.0
22 endif
23 set difference1 = RoundToGetDifference(base, interval)
24 set difference2 = RAbsBJ(interval) - difference1
25 if (difference2 < difference1) then
26 return (base + RSignBJ(interval) * difference2)
27 endif
28 return (base - RSignBJ(interval) * difference1)
29 endfunction
30
31 /**
32 * @author Shadow1500
33 * @source http://www.hiveworkshop.com/
34 * @return Returns the height.
35 */
36 function JumpParabola takes real distance, real maxDistance, real curve returns real
37 local real t = (distance * 2) / maxDistance - 1
38 return (- t * t + 1) * (maxDistance / curve)
39 endfunction
40
41 /**
42 * This function takes as a parameters the distance that the parabolic movement should move (d)
43 * and the maximum height the projectile will flight (h).
44 * So x is a value between 0 and d, and the function will return the height for that value.
45 * As a side note, if x < 0 or x > d then this function will return negative values.
46 * @author moyack
47 * @author Spec
48 * @source http://www.wc3c.net/showthread.php?t=102077
49 */
50 function ParabolaZ takes real maxHeight, real distance, real x returns real
51 return (4 * maxHeight / distance) * (distance - x) * (x / distance)
52 endfunction
53
54 /**
55 * Called ALog since RtC has its own Log function.
56 * @author Vexorian
57 * @source http://www.wc3campaigns.net/
58 */
59 function ALog takes real x, integer iterations returns real
60 local real min = -88.0
61 local real max = 88.0
62 local real mid
63 local integer i = iterations
64 loop
65 set mid = (min + max) / 2
66 exitwhen (i <= 0)
67 set i = i - 1
68 if (Pow(bj_E, mid) >= x) then
69 set max = mid
70 else
71 set min = mid
72 endif
73 endloop
74 return mid
75 endfunction
76
77 /**
78 * @author Vexorian
79 * @source http://www.wc3campaigns.net/
80 */
81 function Logarithm takes real base, real x, integer iterations returns real
82 local real min = -88.0
83 local real max = 88.0
84 local real mid
85 local integer i = iterations
86 loop
87 set mid = (min + max) / 2
88 exitwhen (i <= 0)
89 set i = i-1
90 if (Pow(base, mid) >= x) then
91 set max = mid
92 else
93 set min= mid
94 endif
95 endloop
96 return mid
97 endfunction
98
99 endlibrary